package com.game.view.layer
{
	import com.dusk.util.ResUtil;
	import com.game.engine.MainGame;
	import com.game.manager.GameSceneManager;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.*;
	
	public class GameFail extends LayerBase
	{
		
		public function GameFail()
		{
			super();
		}
		
		private var rePlayBtn:SimpleButton;
		private var backToMapBtn:SimpleButton;
		private var curStage:int;
		private var curLevel:int;
		
		override protected function beforeAdded():void
		{
			var mc:MovieClip = ResUtil.getLayerView("GameFail") as MovieClip;
			rePlayBtn = mc.getChildByName("rePlayBtn") as SimpleButton;
			backToMapBtn = mc.getChildByName("backToMapBtn") as SimpleButton;
			addChild(mc);
		}
		
		override protected function onAdded():void
		{
			curStage = MainGame.getIns().levelData.curStage;
			curLevel = MainGame.getIns().levelData.curLevel;
			this.rePlayBtn.addEventListener(MouseEvent.CLICK, this.rePlay);
			this.backToMapBtn.addEventListener(MouseEvent.CLICK, this.backToMap);
		}
		
		override protected function onRemoved():void
		{
			this.rePlayBtn.removeEventListener(MouseEvent.CLICK, this.rePlay);
			this.backToMapBtn.removeEventListener(MouseEvent.CLICK, this.backToMap);
		}
		
		private function rePlay(param1:*):void
		{
			GameSceneManager.getIns().switchScene(GameSceneManager.START_FIGHTING,curStage + "_" + curLevel);
			removeFromParent();
		}
		
		private function backToMap(param1:*):void
		{
			GameSceneManager.getIns().switchScene(GameSceneManager.GAME_MAP);
			removeFromParent();
		}
	}
}
